<?php
defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * 观点管理控制器-C端
 * 
 * @desc    观点管理
 * @version 1.0.0 直接完善文档注释
 * @date	2017年7月7日 上午10:20:53
 * 
 * @title 观点管理
 * @entry http://discovery.segway.com
 */
class Opinion extends MY_Consumer_Controller
{
	/** @var Lib_opinion */
	public $lib_opinion = null;
	
	/** @var Lib_tag */
	public $lib_tag = null;
	
	public function __construct()
	{
		parent::__construct();
		
		$this->load->library('lib_opinion');
		// Somewhere need lib_tag
		$this->load->library('lib_tag');
		
		$this->set_mutable_view_var('head.title', 'Opinion - Management');
		$this->set_mutable_view_var('head.keywords', '');
		$this->set_mutable_view_var('head.description', '');
		
		$this->lang->load('opinion');
		
	}
	
	
	/**
	 * 提交反馈 - 客户端提交关于网站的反馈
	 * 
	 * @desc	编辑完后的信息提交 - 增加 & 修改
	 * @method	POST
	 * @author	Jason
	 * @date	2017年7月7日 下午4:08:04
	 * 
	 * @param	number $id		 ID，默认为 0，代表增加 & 非0代表修改
	 * ...
	 *
	 * @return	JSON	标准JSON格式响应
	 * 					结构：无
	 * 
	 * @link	/opinion/ajax_create_feedback
	 * 
	 * @command noneurl
	 */
	public function ajax_create_feedback()
	{
		$member_id = $this->get_logined_member()['id'];
		if(empty($member_id)){
			Lib_json::renderSuccess([], 'success');
			return ;
		}
		$constants = [
				'master_id' => NULL,
				'resource_type' => 'feedback',
				'resource_id' => NULL,
				'source_type' => 'member',
				'source_id' => $member_id,
				'target_type' => 'website',
				'target_id' => 0,
				'resource_platform' => 'Web',
				'resource_version' => date('Y-m-d H:i:s'),
				'status_tags' => 'enabled',
		];
		foreach ($constants as $key => $value) {
			$_POST[$key] = $value;
		}
		$_POST['content'] .= date('Y-m-d');
		list($status, $content) = $this->lib_opinion->create();
		
		if(!$status) {
			$messageContent = Lib_json::getMessageContent($content);
			Lib_json::renderError(Lib_json::ERROR_BUSINESS, current($content), $messageContent);
		} else {
			Lib_json::renderSuccess(['data' => $content], 'success');
		}
	}
	
	
}
